/*
Licenta: Palangeanu Lucian
Telefon: 0727 448 535
*/

var device;
var coordonate;
if((/chrome/i.test(navigator.userAgent.toLowerCase()))){
	device = "Web Browser Chrome";
}
if((/android/i.test(navigator.userAgent.toLowerCase()))){
	device = "Android";
}
if((/webos/i.test(navigator.userAgent.toLowerCase()))){
	device = "WebOS";
}
if((/iphone/i.test(navigator.userAgent.toLowerCase()))){
	device = "iphone";
}
if((/ipad/i.test(navigator.userAgent.toLowerCase()))){
	device = "ipad";
}
if((/ipod/i.test(navigator.userAgent.toLowerCase()))){
	device = "ipod";
}
if((/blackberry/i.test(navigator.userAgent.toLowerCase()))){
	device = "blackberry";
}
if((/opera mini/i.test(navigator.userAgent.toLowerCase()))){
	device = "opera mini";
}
if((/windows phone/i.test(navigator.userAgent.toLowerCase()))){
	device = "windows phone";
}
if((/firefox/i.test(navigator.userAgent.toLowerCase()))){
	device = "Firefox";
}
if((/MSIE/i.test(navigator.userAgent.toLowerCase()))){
	device = "Internet Explorer";
}
if((/opera/i.test(navigator.userAgent.toLowerCase()))){
	device = "Opera";
}


var geocoder;
if(navigator.geolocation){
    navigator.geolocation.getCurrentPosition(successFunction, errorFunction);
}else{
	latlng = 'err';
	adresa =  'err';
	coordonate =  'err';
}

function successFunction(position){
    var lat = position.coords.latitude;
    var lng = position.coords.longitude;
    codeLatLng(lat, lng)
}

function errorFunction(){
	latlng = 'err';
	adresa =  'err';
	coordonate =  'err';
}

function initialize() {
    geocoder = new google.maps.Geocoder();
}

function codeLatLng(lat, lng) {
	latlng = new google.maps.LatLng(lat, lng);
	geocoder.geocode({'latLng': latlng}, function(results, status) {
		adresa = results[1].formatted_address;
		coordonate = new String(results[1].geometry.location);
		
	});
}

//ajax trimite informatii
$(".raspuns").click(function(){
	intensitate = $(this).attr("id");
	ip_user = $("#user_ip").val();
	var eveniment = $("#eveniment").val();
	$( "#comentariu" ).dialog();
	$.ajax({
		type:"POST",
		url:"ajax.php",
		data:{"intensitate":intensitate,"user_ip":ip_user,"eveniment":eveniment,"adresa":adresa,"latlng":coordonate,"device":device}
	}).done(function(id_insert){
		
			$(".trimite").click(function(){
				if($.isNumeric(id_insert)){
					comm = $(".textuser").val();
					$.ajax({
						type:"POST",
						url:"ajax.php",
						data:{"comentariu":comm,"id_insert":id_insert}
					}).done(function(){
							$( "#comentariu" ).dialog("close" );
							$( "#msg" ).dialog().html();
					})
				}else{
					$( "#comentariu" ).dialog("close" );
					$( "#msg" ).dialog().html('<p style="text-align:center;">Puteti raspunde doar o singura data per eveniment.</p> <p style="text-align:center;">Multumim!</p>');
				}

			})	
		
	})
});
